import { ProFormTreeSelect } from '@ant-design/pro-components';
import { type RefSelectProps, type TreeSelectProps } from 'antd';
import type { ProFormFieldRemoteProps } from '@ant-design/pro-form/lib/interface';
import { type ProFormFieldItemProps } from '@ant-design/pro-form/lib/interface';
const CommonFormTreeSelect: React.FC<
  ProFormFieldItemProps<TreeSelectProps<any>, RefSelectProps> & ProFormFieldRemoteProps
> = ({ required, rules = [], ...props }) => {
  return (
    <>
      <ProFormTreeSelect
        {...props}
        rules={
          rules.some((rule) => 'required' in rule)
            ? rules
            : [
                {
                  required,
                  message: `请选择${props.label}`,
                },
                ...rules,
              ]
        }
      />
    </>
  );
};

CommonFormTreeSelect.defaultProps = { required: false, placeholder: '' };

export default CommonFormTreeSelect;
